// 单据类页面的操作按钮
import operationBar from './index';
export default {
	components: { operationBar },
	data() {
		return {};
	},
	methods: {
		validateTablePass() {
			return true;
		},
		handlerResOfDetailPage(res, type) {
			if (res.data.status === 200) {
				this.$tipsBar(this, type);
				this.showLoading = true;
				this.getDetailRequest();
			}
		},
		/** 新增、编辑页的操作栏事件 */
		onOperationBarEventOfAddOrEditPage(state, type) {
			this.$refs['ruleForm'].validate(valid => {
				if (valid) {
					if (!this.validateTablePass()) return;
					// 只改状态
					if (type === 'cancelSubmit' || type === 'cancelAudit' || type === 'cancelClose') {
						this.apiItem[type]({
							id: this.ruleForm.id,
							version: this.ruleForm.version
						}).then(res => {
							this.handlerResOfAddOrEditPage(res, type);
						});
					} else if (type === 'submit') {
						// 提交
						const cpData = this.setDependentDataOfForm();
						cpData.auditState = 2;
						this.apiItem[type](cpData).then(res => {
							this.handlerResOfAddOrEditPage(res, type);
						});
					} else {
						// 创建和更新
						const cpData = this.setDependentDataOfForm();
						this.apiItem[type](cpData).then(res => {
							this.handlerResOfAddOrEditPage(res, type);
						});
					}
				} else {
					this.$tipsBar(this, 'validator');
				}
			});
		},
		/** 详情页的操作栏事件 */
		onOperationBarEventOfDetailPage(e, type) {
			this.apiItem[type]({ ...e, id: this.dataId, version: this.ruleForm.version }).then(res => this.handlerResOfDetailPage(res, type));
		},
		handlerResOfAddOrEditPage(res, type) {
			if (res.data.status === 200) {
				this.$tipsBar(this, type);
				this.onJump();
			}
		}
	}
};
